package com.chey.controller;

import com.chey.domain.Flight;
import com.chey.domain.Pages;
import com.chey.domain.QueryData;
import com.chey.domain.ResponseData;
import com.chey.service.ShowService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.CoercionConfig;
import com.fasterxml.jackson.databind.cfg.CoercionConfigs;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author JanYao
 * @version 0.1
 */
@RestController
public class ShowController {

    @Autowired
    private ShowService showService;

    @RequestMapping("/some")
    public ResponseData show(Pages pages,
                             @RequestParam(value = "input", required = false) String input) {
        System.out.println("page:" + pages.getPage() + "pageSize:" + pages.getPageSize());
        QueryData queryData = null;
        System.out.println(input);


                try {

                    queryData = new ObjectMapper().readValue(input, QueryData.class);
                    System.out.println(queryData);
                } catch (JsonProcessingException e) {
                    e.printStackTrace();
                }




        pages.setPage((pages.getPage() - 1) * pages.getPageSize());
        Pages page = showService.findSome(pages, queryData);
        ResponseData data = new ResponseData();
        data.setCode(200);
        data.setData(page);
        System.out.println(data);
        return data;
    }
}
